//
//  ViewController.m
//  UI___14HomeWork 礼物说分类界面
//
//  Created by 冀永金 on 16/8/2.
//  Copyright © 2016年 冀永金. All rights reserved.
//

#import "ViewController.h"
#import "SortCollectionViewCell.h"
#import "LabelCollectionReusableView.h"
#import "ColumnCollectionReusableView.h"

@interface ViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake((self.view.bounds.size.width - 30) / 2, (self.view.bounds.size.width - 30) / 4);
    layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    UICollectionView *collection = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width,self.view.bounds.size.height) collectionViewLayout:layout];
    [self.view addSubview:collection];
    collection.delegate = self;
    collection.dataSource = self;
    [collection registerClass:[SortCollectionViewCell class] forCellWithReuseIdentifier:@"poolOfSort"];
    collection.backgroundColor = [UIColor whiteColor];
    [collection registerClass:[LabelCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"poolOfHeader"];
    [collection registerClass:[ColumnCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"poolOfFirstHeader"];
       // Do any additional setup after loading the view, typically from a nib.
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 4;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if (section == 0) {
        return 0;
    } else {
    return 6;
    }
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    SortCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"poolOfSort" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor yellowColor];
    return cell;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        ColumnCollectionReusableView *column = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"poolOfFirstHeader" forIndexPath:indexPath];
        column.backgroundColor = [UIColor whiteColor];
        return column;
    }
    else {
        LabelCollectionReusableView *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"poolOfHeader" forIndexPath:indexPath];
        //header.backgroundColor = [UIColor blueColor];
        return header;
    }
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return CGSizeMake(0, 350);
    }else {
    return CGSizeMake(0, 50);
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
